package com.pm.controller;

import com.pm.common.annotation.Log;
import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.core.page.TableDataInfo;
import com.pm.common.enums.BusinessType;
import com.pm.common.utils.poi.ExcelUtil;
import com.pm.domain.PmUser;
import com.pm.service.IPmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 顾客管理Controller
 * 
 * @author ruoyi
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/pm/user")
public class PmUserController extends BaseController
{
    @Autowired
    private IPmUserService pmUserService;

    /**
     * 查询顾客管理列表
     */
    @PreAuthorize("@ss.hasPermi('pm:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmUser pmUser)
    {


        startPage();
        List<PmUser> list = pmUserService.selectPmUserList(pmUser);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setVipName(pmUserService.getUserVipAll(list.get(i).getVipId()));
        }
        return getDataTable(list);
    }


    /**
     * 导出顾客管理列表
     */
    @PreAuthorize("@ss.hasPermi('pm:user:export')")
    @Log(title = "顾客管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmUser pmUser)
    {
        List<PmUser> list = pmUserService.selectPmUserList(pmUser);
        ExcelUtil<PmUser> util = new ExcelUtil<PmUser>(PmUser.class);
        util.exportExcel(response, list, "顾客管理数据");
    }

    /**
     * 获取顾客管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pm:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmUserService.selectPmUserById(id));
    }

    /**
     * 新增顾客管理
     */
    @PreAuthorize("@ss.hasPermi('pm:user:add')")
    @Log(title = "顾客管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmUser pmUser)
    {
        return toAjax(pmUserService.insertPmUser(pmUser));
    }

    /**
     * 修改顾客管理
     */
    @PreAuthorize("@ss.hasPermi('pm:user:edit')")
    @Log(title = "顾客管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody  PmUser pmUser)
    {
        return toAjax(pmUserService.updatePmUser(pmUser));
    }

    /**
     * 删除顾客管理
     */
    @PreAuthorize("@ss.hasPermi('pm:user:remove')")
    @Log(title = "顾客管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmUserService.deletePmUserByIds(ids));
    }



}
